import { createApp } from "vue";
import Root from "./App.vue";
import type { App } from "vue";
import pinia from "./store";
import hasPers from "./utils/hasPermi";
import router from "@/router";
import "@/router/router-guard";

import "./assets/styles/index.less";

function ininComponent(app: App) {
  // 动态注册公共组件
  const requireComponent = import.meta.glob("./components/global/*/*.*");
  Object.keys(requireComponent).forEach(item => {
    const componentConfig = requireComponent[item];
    // @ts-ignore
    const name = item.split("/").pop().split(".")[0];
    // @ts-ignore
    app.component(name, componentConfig.default || componentConfig);
  });
}

async function start() {
  const app = createApp(Root);
  app.use(pinia);
  app.directive("hasPermi", hasPers);
  ininComponent(app);
  app.use(router);
  app.mount("#app");
}
start();
